require(["./config"], ()=> {
    require(['template','jquery'], (template) => {
        class register {
            constructor () {
                this.reginput()
                this.userregister()
            }
            reginput () {
                $('#usa').on('click', () => {
                    $("#usa").addClass('ac')
                    $('#usb').removeClass('ac')
                    $('#iphone-num').attr('style','display:none;')
                    $('#chenkdel').attr('style','display:none;')
                    $('#iphone-email').attr("placeholder","请输入手机号")
                })
                $('#usb').on('click', () => {
                    $("#usb").addClass('ac')
                    $('#usa').removeClass('ac') 
                    $('#iphone-num').attr('style','display:block;')
                    $('#chenkdel').attr('style','display:block;')
                    $('#iphone-email').attr("placeholder","请输入邮箱账号")
                })
            }
            userregister () {
               $('#user-bot-btn').on('click', ()=> {
                const username = $('#iphone-email').val()
                const password = $('#user-pwd').val()
                if(username.length > 0 && password.length > 0 ) {
                    const userinfo = { username, password }
                    var userList = localStorage.getItem('userinfo')
                    if(userList) {
                    userList = JSON.parse(userList)
                    const isExist = userList.some(user => user.username === username)
                    // console.log(isExist)
                    if(isExist) {
                    //    console.log($('#deiger'))
                    $('#deiger').attr('style','display:block;')
                    setTimeout(()=> {
                        $('#deiger').attr('style','display:none;')
                    },3000)
                    return
                    }  else {    
                    userList.push(userinfo)
                    localStorage.setItem('userinfo', JSON.stringify(userList))
                    $('#dager').attr('style','display:block;')
                    setTimeout(()=> {
                        $('#dager').attr('style','display:none;')
                        setTimeout(()=>{
                            window.open('/index.html','_self')
                        },1000)
                     },1000)
                   
                    }
                }else {
                    var arr = [ userinfo ]
                    localStorage.setItem('userinfo', JSON.stringify(arr))
                    $('#dager').attr('style','display:block;')
                    setTimeout(()=> {
                        $('#dager').attr('style','display:none;')
                        setTimeout(()=>{
                            window.open('/index.html','_self')
                        },1000)
                    },1000)
                }
                }else{
                    $('#show-num-user-infor').attr('style','display:block;')
                    setTimeout(()=>{
                        $('#show-num-user-infor').attr('style','display:none;')
                    },3000)
                }
                
               })
            }
        }
        new register()
    })
})